/*
 * Copyright (c) 2013, FPX and/or its affiliates. All rights reserved.
 * Use, Copy is subject to authorized license.
 */
package pyip.lib.mixtool.io;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yepeng
 * @date 2015年1月13日
 */
public class FileUtils2 {

    private static final Logger log = LoggerFactory.getLogger(FileUtils2.class);

    public static String getString(String file) throws IOException {
        InputStream in = null;
        BufferedReader br = null;
        try {
            StringBuffer sbuff = new StringBuffer();

            in = new FileInputStream(file);
            br = new BufferedReader(new InputStreamReader(in));
            int size = 0;
            char[] cbuf = new char[1024];
            while ((size = br.read(cbuf)) != -1) {
                sbuff.append(cbuf, 0, size);
            }

            return sbuff.toString();
        } finally {
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                    log.error("", e);
                }
            }
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    log.error("", e);
                }
            }
        }
    };
}
